var GameData = require('../module/gameData')();
cc.Class({
    extends: cc.Component,

    properties: {
        c_num: cc.Label,
        combo: cc.Node,
        jindu: cc.Sprite,
        _dt: 0,
        // star: dragonBones.ArmatureDisplay,
        star: cc.ParticleSystem,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.reset();

        // this.star.addEventListener(dragonBones.EventObject.LOOP_COMPLETE, this.starPlay, this);
    },
    playGame() {
        let _t = 0.2;
        var that = this;
        this.node.x = -341;
        this.node.y = 200;

        this.node.scale=1.5;
        that.playStart();
        this.node.runAction(cc.sequence(
            cc.fadeIn(0),
            cc.scaleTo(0.2,0.9),
            cc.scaleTo(0.05,1),
            cc.callFunc(function () {
                that._start = true;
            })
        ))
    },
    starPlay() {
        this.star.node.active = false;
    },
    playStart() {
        var that = this;
        this.star.node.runAction(cc.sequence(
            cc.callFunc(function () {
                that.star.resetSystem();
            }),
            cc.delayTime(1),
            cc.callFunc(function () {
                that.star.stopSystem();
            })
        ))
    },
    Nodefadeout() {
        this._start = false;
        this.reset();
        GameData.GameLayer.comboCount = 0;
        this.count = 0;
        this.node.runAction(
            cc.fadeOut(0.5)
        )
    },
    reset() {
        this.count = 0;
        this.node.scale=1.5;
        this._start = false;
        this._dt = 0;
        this.jinduT = 3;
        this.jinduW = 100;
        this.jindu.node.width = this.jinduW;
    },

    start() {

    },
    run() {
        var that = this;
        this.node.stopAction();
        this.node.runAction(
            cc.spawn(
                cc.sequence(
                    cc.scaleTo(0.2, 1.2, 1.2),
                    cc.delayTime(0.1),
                    cc.scaleTo(0.1, 1, 1),
                ),
                cc.callFunc(
                    that.playStart()
                )
            ))
    },


    update(dt) {
        if (this.count < GameData.GameLayer.comboCount) {
            this.playGame();
            // if (this.count == 0) {
            //     this.playGame();
            // } else {
            //     this.playGame()
            // }
            this.jindu.node.width = this.jinduW;
            this.count = GameData.GameLayer.comboCount;
            this.c_num.string = GameData.GameLayer.comboCount + "";
        }
        if (this._start) {
            this._dt += dt;
            if (this._dt >= this.jinduT / 10) {
                this.jindu.node.width -= this.jinduW / 10;
                this._dt = 0;
                if (this.jindu.node.width <= 0) {
                    this.jindu.node.width = 0;
                    this.Nodefadeout();
                }
            }
        }

    }
});
